package com.bys.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bys.security.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyBatisMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("createBy", SecurityUtils.getUserId(),metaObject);
        this.setFieldValByName("updateBy", SecurityUtils.getUserId(),metaObject);
        this.setFieldValByName("isDeleted", Boolean.FALSE,metaObject);

    }



    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateBy", SecurityUtils.getUserId(),metaObject);
    }
}
